public class Test04 {

    public static void main(String[] args) {

        Login login = new Login();
        String name = "admin";
        String password = "12345";
        try {
            login.loginInfo(name, password);
        } catch (UserNameException e) {
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }
}

class Login{
    private String username = "admin";
    private String password = "123456";

    public void loginInfo(String username, String password) throws UserNameException,PasswordException{

        if(!this.username.equals(username)){
            throw new UserNameException("用户名错误");
        }

        if(!this.password.equals(password)){
            throw new PasswordException("密码错误");
        }

        System.out.println("登录成功");

    }
}

class UserNameException extends Exception{
    public UserNameException(String message){
        super(message);
    }
}

class PasswordException extends Exception{
    public PasswordException(String message){
        super(message);
    }
}
